package exam.web.action;

import java.util.List;

import exam.business.service.ExaminationGetService;
import exam.common.key.KeyExamination;
import exam.common.key.KeyQuestion;
import exam.common.util.KeyCommon;
import exam.common.util.NullCheckUtil;
import exam.model.entity.TAnswerEntity;
import exam.model.entity.TExaminationEntity;
import exam.model.entity.TQuestionEntity;
import exam.web.action.base.ExaminationActionBase;

/**
 * <p>ViewExaminationAction</p>
 * <p>Action hiển thị thông tin đề thi</p>
 * 
 * @author Phong
 * @version 5/5/2012
 */
public class ViewExaminationAction extends ExaminationActionBase {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	public String execute() throws Exception {
		// get examId
		String examId = request.getParameter(KeyCommon.EXAM_ID);
		if(NullCheckUtil.isNull(examId)) {
			return ERROR;
		}
		// put examId vao serviceInfo
		serviceInfo.put(KeyExamination.EXAM_ID, examId);
		// yeu cau lay de thi
		ExaminationGetService examinationGetService = new ExaminationGetService();
		String port = examinationGetService.executeService(serviceInfo);
		if(NONE.equals(port)) {
			return NONE;
		} else {
			// lay tExaminationEntity tu serviceInfo
			TExaminationEntity tExaminationEntity = serviceInfo.getObject(KeyExamination.T_EXAMINATION_ENTITY);
			// copy thuoc tinh
			copyFromTExaminationEntity(tExaminationEntity);
			// lay tQuestionEntityList tu serviceInfo
			List<TQuestionEntity> tQuestionEntityList = serviceInfo.getList(KeyQuestion.T_QUESTION_ENTITY_LIST);
			request.setAttribute(KeyQuestion.T_QUESTION_ENTITY_LIST, tQuestionEntityList);
			// lay tAnswerEntityList tu serviceInfo
			List<TAnswerEntity> tAnswerEntityList = serviceInfo.getList(KeyQuestion.T_ANSWER_ENTITY_LIST);
			request.setAttribute(KeyQuestion.T_ANSWER_ENTITY_LIST, tAnswerEntityList);
		}
		return SUCCESS;
	}
}
